package com.yvtian.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yvtian.admin.pojo.SysDept;
import com.yvtian.admin.pojo.SysUser;
import com.yvtian.admin.service.SysDeptService;
import com.yvtian.annotation.Log;
import com.yvtian.annotation.PreAuthorize;
import com.yvtian.entity.Result;
import com.yvtian.entity.StatusCode;
import com.yvtian.enums.OperatorType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * (sys_dept)表控制层
 *
 * @author long
 * @since 2024-04-06 14:28:54
 */
@RestController
@RequestMapping("sysDept")
public class SysDeptController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private SysDeptService sysDeptService;


    @Log(value = "分页查询部门")
    @GetMapping(value = "/list")
    public Result findByPage(Page<SysDept> page, SysDept sysDept) {
        return new Result(true, "查询成功", StatusCode.OK, sysDeptService.findByPage(page,sysDept));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable Serializable id) {
        return new Result(true, "查询成功", StatusCode.OK, sysDeptService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysDept 实体对象
     * @return 新增结果
     */
    @Log(value = "添加部门",isSave = true,operType = OperatorType.INSERT)
    @PostMapping("insert")
    public Result insert(@RequestBody SysDept sysDept) {
        sysDept.setCreateTime(new Date());
        return new Result(true, "插入成功", StatusCode.OK, this.sysDeptService.save(sysDept));
    }

    /**
     * 修改数据
     *
     * @param sysDept 实体对象
     * @return 修改结果
     */
    @Log(value = "修改角色",isSave = true,operType = OperatorType.UPDATE)
    @PostMapping("update")
    public Result update(@RequestBody SysDept sysDept) {
        sysDept.setUpdateTime(new Date());
        return new Result(true, "更新成功", StatusCode.OK, this.sysDeptService.updateById(sysDept));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @Log(value = "删除角色",isSave = true,operType = OperatorType.DELETE)
    @PostMapping("del")
    public Result delete(@RequestParam("idList") List<Long> idList) {
        return new Result(true, "删除成功", StatusCode.OK, this.sysDeptService.removeByIds(idList));
    }
}

